<!-- 账户汇总--付款预估收益明细 -->
<template>
  <div>
    <div class="table-page-search">
      <a-form>
        <a-form-item label="关键词搜索">
          <a-input v-model="queryParam.keyWord" placeholder="请输入" allowClear />
        </a-form-item>
        <a-form-item label="收益类型">
          <a-select v-model="queryParam.incomeType" placeholder="请选择" allowClear>
            <a-select-option v-for="item in Dictionary.getLocal('IncomeTypeEnum')" :key="item.dictValue"
              :value="item.dictValue">{{
                item.dictLabel
              }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="下单时间">
          <a-range-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="applyTime" class="width-25" />
        </a-form-item>
        <span class="search-submitButtons">
          <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
          <a-button @click="handleReset">重置</a-button>
        </span>
      </a-form>
    </div>
    <s-table ref="table" size="default" rowKey="id, enabled, title" :columns="columns" :data="loadData"
      :rowSelection="null">
      <span slot="totalAmount" slot-scope="text">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>

      <span slot="payAmount" slot-scope="text, record">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>

      <span slot="distributionAmount" slot-scope="text">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>
    </s-table>
  </div>
</template>

<script>
import { STable } from '@/components'
import { resourcesIncomeList } from '@/api/finance/finance'
import Dictionary from "@/utils/dict/Dictionary";
import { formatMoney } from "@/utils/number";
export default {
  components: {
    STable,
  },
  data() {
    return {
      Dictionary,
      pagination: {
        current: 1,
        pageSize: 10,
      },
      queryParam: {
        keyWord: undefined,
        incomeType: undefined,
        startTime: undefined,
        endTime: undefined,
      },
      columns: [
        {
          title: '订单编号',
          dataIndex: 'orderNo',
          width: '220px',
        },
        {
          title: '子订单编号',
          dataIndex: 'suborderNo',
          ellipsis: true,
          width: '220px',
        },
        {
          title: '产品ID',
          dataIndex: 'productId',
          ellipsis: true,
          width: '120px',
        },
        {
          title: '产品来源',
          dataIndex: 'productSourceName',
          ellipsis: true,
          width: '100px',
        },
        {
          title: '应付金额',
          ellipsis: true,
          dataIndex: 'totalAmount',
          width: '120px',
          scopedSlots: { customRender: 'totalAmount' },
        },
        {
          title: '实付金额',
          dataIndex: 'payAmount',
          ellipsis: true,
          scopedSlots: { customRender: 'payAmount' },
          width: '120px',
        },
        {
          title: '预估收益（待结算）',
          dataIndex: 'distributionAmount',
          scopedSlots: { customRender: 'distributionAmount' },
          ellipsis: true,
          width: '120px',
        },
        {
          title: '收益类型',
          dataIndex: 'incomeTypeName',
          ellipsis: true,
          width: '120px',
        },
        {
          title: '支付时间',
          dataIndex: 'payTime',
          ellipsis: true,
          width: '150px',
        },
      ],
      pageNum: 1,
      // 加载数据方法 必须为 Promise 对象
      loadData: async (parameter) => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize,
        }
        return resourcesIncomeList(Object.assign(params, this.queryParam))
          .then((res) => {
            if (res.code === 0) {
              this.pagination.current = parameter.pageNum
              this.pagination.pageSize = parameter.pageSize
              return res
            } else {
              this.$message.error(res.msg)
            }
          })
          .catch((err) => {
            this.$message.error(err.msg)
          })
      },
    }
  },
  computed: {
    applyTime: {
      get() {
        return [this.queryParam.startTime, this.queryParam.endTime]
      },
      set(val) {
        this.queryParam.startTime = val[0]
        this.queryParam.endTime = val[1]
      },
    },
  },
  created() { },
  methods: {
    formatMoney,
    handleReset() {
      Object.keys(this.queryParam).forEach((k) => {
        this.queryParam[k] = undefined
      })
      this.$refs.table.refresh(true)
    },
  },
}
</script>
<style scoped lang="less"></style>
